﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Olympic_email_to_future.Module;

namespace FutureMeWeb
{
    public partial class modify_password : System.Web.UI.Page
    {
        public Olympic_email_to_future.IBLL.IUserBLL bll = Olympic_email_to_future.BLLFactory.BusinessFactory.CreateUserBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != null)
            {
                UserInfo user = (UserInfo)Session["User"];
                AccountBtn.Text = user.userMailAddress;
                LoginBtn.Visible = false;
                RegisterBtn.Visible = false;
            }
            else
            {
                AccountBtn.Visible = false;
                LogoffBtn.Visible = false;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UserInfo user=new UserInfo();
            UserInfo userinfo = (UserInfo)Session["User"];
            userinfo.userPassword = TextBox1.Text;
            user.userMailAddress = userinfo.userMailAddress;
            if (bll.checkPassword(userinfo))
            {
                if (TextBox2.Text == TextBox3.Text)
                {
                    user.userPassword = TextBox2.Text;
                    bll.modify_password(user);
                    Session.Abandon();
                    Response.Write("<script>alert('修改成功，请重新进行登录');location.href='login.aspx';</script>"); ;
                }
                else
                    Response.Write("<script>alert('新密码输入不一致，请重新输入')</script>");
            }
            else
                Response.Write("<script>alert('原密码输入不正确，请重新输入')</script>");
        }

        protected void LogoffBtn_Click(object sender, EventArgs e)
        {
            Session.Abandon();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
        }
       
    }
}